using NUnit.Framework;
using poba.Core.Drivers;
using poba.Core.Html;
using poba.tests.Core;

namespace poba.tests.UnitTests.Core.Html {
    [TestFixture]
    public class TestElement {
        private IEDriverBase _driver;
        private string _testDataFile;

        public TestElement() {
            _testDataFile = Utils.GetClassDirectory(GetType()) + "TestElementData.htm";
        }

        [SetUp]
        public void SetUp() {
            _driver = new IEDriverBase();
            _driver.Navigate(_testDataFile);
        }

        [TearDown]
        public void TearDown() {
            _driver.Close();    
        }

        [Test]
        public void ClassName() {
            Assert.AreEqual("SomeClass", _driver.GetElementById("SomeId").ClassName);
        }

        [Test]
        public void ID() {
            Assert.AreEqual("SomeId", _driver.GetElementById("SomeId").ID);
        }

        [Test]
        public void InnerHtml() {
            Assert.AreEqual("<B>some bold text</B>", _driver.GetElementById("SomeId").InnerHTML);
        }

        [Test]
        public void InnerText() {
            Assert.AreEqual("some bold text", _driver.GetElementById("SomeId").InnerText);
        }

        [Test]
        public void OffsetHeight() {
            // TODO: Need to implement better tests
            Assert.AreEqual(20, _driver.GetElementById("SomeId").OffsetHeight);
            Assert.AreEqual(19, _driver.GetElementById("SecondDivId").OffsetHeight);
        }

        [Test]
        public void OffsetLeft() {
            // TODO: Need to implement tests
        }

        [Test]
        public void OffsetParent() {
            // TODO: Need to implement tests
        }

        [Test]
        public void OffsetTop() {
            // TODO: Need to implement tests
        }

        [Test]
        public void OffsetWidth() {
            // TODO: Need to implement tests
        }

        [Test]
        public void ParentElement() {
            Assert.AreEqual("ParentDiv", _driver.GetElementById("ChildDiv").ParentElement.ID);
        }

        [Test]
        public void Style() {
            // TODO: Need to implement tests
        }

        [Test]
        public void TagName() {
            Assert.AreEqual("DIV", _driver.GetElementById("ChildDiv").TagName);
        }

        [Test]
        public void Click() {
            _driver.GetElementById("ClickAnchor").Click();
            Assert.AreEqual("Clicked", _driver.GetElementById("ClickResult").InnerText);
        }

        [Test]
        public void Contains() {
            Element parent = _driver.GetElementById("ParentDiv");
            Element child = _driver.GetElementById("ChildDiv");
            Assert.IsTrue(parent.Contains(child));
        }

        [Test]
        public void GetAttribute() {
            Assert.AreEqual("Attribute1", _driver.GetElementById("Attribute").GetAttribute("attr1"));
            Assert.AreEqual("", _driver.GetElementById("Attribute").GetAttribute("NotExist"));
        }

        [Test]
        public void RemoveAttribute() {
            _driver.GetElementById("Attribute").RemoveAttribute(("attr1"));
            Assert.AreEqual("", _driver.GetElementById("Attribute").GetAttribute("attr1"));
        }

        [Test]
        public void SetAttribute() {
            _driver.GetElementById("Attribute").SetAttribute("attr2", "Second Attribute");
            Assert.AreEqual("Second Attribute", _driver.GetElementById("Attribute").GetAttribute("attr2"));
        }

        [Test]
        public void CreateMostSpecificType() {
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("DivType").HtmlElement) is Element);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("AnchorType").HtmlElement) is AnchorElement);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("TextType").HtmlElement) is TextBoxElement);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("CheckBoxType").HtmlElement) is CheckBoxElement);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("RadioType").HtmlElement) is RadioButtonElement);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("SelectType").HtmlElement) is SelectElement);
            Assert.IsTrue(Element.CreateMostSpecificType(_driver.GetElementById("OptionType").HtmlElement) is OptionElement);
        }

    }
}